package com.jic.market.impl.coupon;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.coupon.CouponGoods;
import com.jic.market.mapper.coupon.CouponGoodsMapper;
import com.jic.market.service.coupon.CouponGoodsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 优惠券商品关联表
 * @author : seven
 * @email : 774329481@qq.com
 * @since : 2020-03-15 08:24:22
 * @version : v1.0.0
 */
@Service
public class CouponGoodsServiceImpl implements CouponGoodsService {

    @Autowired
    private CouponGoodsMapper couponGoodsMapper;

    @Override
    public Long insert(CouponGoods couponGoods) {
        couponGoods.setDeleteFlag(false);
        long flag = couponGoodsMapper.insert(couponGoods);
        return flag;
    }

    @Override
    public Long delete(String promotionId) {
        return couponGoodsMapper.delete(Long.valueOf(promotionId));
    }

    @Override
    public Long update(CouponGoods couponGoods) {
        return couponGoodsMapper.update(couponGoods);
    }

    @Override
    public CouponGoods queryByPrimaryKey(Long id){
        return couponGoodsMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CouponGoods> query(CouponGoods couponGoods){
        return couponGoodsMapper.query(couponGoods);
    }

    @Override
    public PageResult<CouponGoods> queryPage(CouponGoods couponGoods, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CouponGoods> list = couponGoodsMapper.queryPage(startIndex, pageQuery.getLimit(), couponGoods);
        long count = couponGoodsMapper.queryPageCount(couponGoods);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}